/*
 * TraceNode.cpp
 *
 *  Created on: 7 Dec 2010
 *      Author: kn308
 */

#include <MAlice/TraceNode.h>
#include <MAlice/Trace.h>
#include <MAlice/Parser/location.hh>

using namespace yy;

TraceHandler::TraceHandler(TraceNode* node_) :
	node(node_)
{
	Trace::getTrace()->push(node);
}

TraceHandler::~TraceHandler()
{
	Trace::getTrace()->pop();
}

TraceNode::TraceNode(const char* file, int lineNumber,
		const char* functionName, location location) :
	mFile(file), mLine(lineNumber), mFunc(functionName), mLocation(location)
{
}

TraceNode::~TraceNode()
{
}

void TraceNode::print(std::ostream& os, int indent)
{
	if(indent != 0)
		os << "+-";
	while (indent--)
		os << "--";

	const int line = mLine;
	const string* file = &mFile;
	const string* func = &mFunc;
	const location* loc = &mLocation;

	os << *file << ':' << line << ' ' << *func << ": [" << *loc << ']' << endl;
}
